//Clear all data
clear all

//Set numeric type
set type double

//Set width of figure
local widthPix = 5000


// Change directory - Alter this command to the local copy of the "PrimaryModel" directory
cd "/Users/connorforsythe/Library/CloudStorage/Box-Box/CMU/Marginal Mileage Project/Publication Replication Code/JAERE/PrimaryModel"
//Prevent graphics from popping up while running code
set graphics off

//Always close log regardless of error
capture log close
//determine log location depending on OS
if("`c(os)'"=="Windows"){
	log using "Logs\PrimaryModel.smcl", replace
	local tableSaveDir = "Tables\"
	local plotSaveDir = "Plots\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	log using "Logs/PrimaryModel.smcl", replace
	local tableSaveDir = "Tables/"
	local plotSaveDir = "Plots/"
	local pythonSaveDir = "PythonScripts/"
}


//Start Timer
timer on 1 

//Set seed for replication
set seed 2025

//Load useful programs
do programs

//Execute Stata Do File to load and clean the data for VMT models
do LoadDataVMT

//Execute Stata do file to estimate diff-in-diff models
do RegDiD

//Execute Stata do file to estimate Reduced Form models
do VMTRFDiD

//Execute Stata do file to estimate robust IV for VMT model
do VMTIV

//Execute Stata do file to estimate event studies
do RegES
//
//Execute Stata do file to estimate event studies without time trends
do RegESWoTT

//Execute Stata do file to estimate VMT reduced form event studies
do VMTRFES

//Execute Stata Do File to load and clean the data for fuel use models
do LoadDataGasUse

//Execute Stata do file to estimate robust IV for VMT model
do GasUseIV

//Execute Stata do file to estimate Reduced Form models with gas use axs the outcome variable
do GasUseRFDiD

//Execute Stata do file to estimate VMT reduced form event studies
do GasUseRFES


// Run LOO Analyses for Gas Use IV Models
do GasUseIVLOO
//
//Run LOO Analyses for VMT IV Models
do LoadDataVMT
do VMTIVLOO

// Run Randomized Treatment Analysis
do RandTreatSimReg

//Summarize Randomized Treatment Analysis
do SummarizeRandTreatment

// run neighboring state analysis registrations and VMT
do LoadDataVMT
do neighborStateAnalysis

do LoadDataVMT

do neighborStateAnalysisVMT


do LoadDataGasUse

do neighborStateAnalysisGasUse

//Output Summary from LOO analysis
do summarizeLOO


// Run externality analysis
do externalityAnalysis

// Run Goodman-Bacon Analysis
do BaconEstimation


//Joint estimation of reduced form
do LoadDataJoint
do CompositionAnalysis


//End Timer
qui timer off 1
qui timer list 1
local minToComplete = `r(t1)'/60
if(`r(t1)'<60){
	di "Script took `r(t1)' seconds to complete."	
}
else{
	di "Script took `minToComplete' minutes to complete."	
}

cd "Logs"

translate "PrimaryModel.smcl" "PrimaryModel.pdf", replace

log close
